class BusinessException(Exception):
    """业务逻辑异常"""
    
    def __init__(self, status_or_message, message: str = None, data: dict = None):
        # 兼容两种调用方式：
        # 1. BusinessException("message") - 只传消息
        # 2. BusinessException(StatusCodeEnum.XXX, "message") - 传状态码和消息
        if message is None:
            # 第一种方式：只传消息
            self.message = str(status_or_message)
            self.code = 'BUSINESS_ERROR'
        else:
            # 第二种方式：传状态码和消息
            self.message = message
            if hasattr(status_or_message, 'value') and isinstance(status_or_message.value, tuple):
                # 处理ResponseStatus枚举
                self.code = str(status_or_message.value[0])
            else:
                self.code = str(status_or_message)
        
        self.data = data or {}
        super().__init__(self.message)
    
    def __str__(self):
        return self.message
    
    def to_dict(self):
        """转换为字典格式"""
        return {
            'error_type': 'BusinessException',
            'message': self.message,
            'code': self.code,
            'data': self.data
        }


class ValidationException(BusinessException):
    """数据验证异常"""
    
    def __init__(self, message: str, data: dict = None):
        super().__init__('VALIDATION_ERROR', message, data)
    
    def to_dict(self):
        """转换为字典格式"""
        return {
            'error_type': 'ValidationException',
            'message': self.message,
            'code': self.code,
            'data': self.data
        }